package com.springbootblog.service.serviceImpl.fontend;

import com.springbootblog.controller.fontend.IndexController;
import com.springbootblog.dao.LabelDao;
import com.springbootblog.pojo.Label;
import com.springbootblog.service.fontend.LabelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

@Service
public class LabelServiceImpl implements LabelService
{
    /**
     * 定义一个静态常量日志对象
     */
    private static final Logger logger = LoggerFactory.getLogger(IndexController.class);

    /**
     * 自动装载（dao接口注入）
     */
    @Autowired
    private LabelDao labelDao;

    @Override
    public Map<String, Object> getLabelList()
    {
        // 查标签数量
        Integer count = labelDao.getLabelCount();
        // System.out.println(count);
        // 查标签列表
        List<Label> labelList = labelDao.getLabelList();
        for (int i = 0; i < labelList.size(); i++)
        {
            labelList.get(i).setLabel("tag" + new Random().nextInt(7 - 1 + 1) + 1);
            // .out.println(labelList.get(i));
        }
        Map<String, Object> result = new HashMap<>(4);
        result.put("code", 1);
        result.put("msg", "操作成功");
        result.put("labelList", labelList);
        result.put("count", count);
        return result;
    }


}
